﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessLogic;
using JScripter;
using DataEntity;
using BusinessLogic.Controller;

public partial class Admin_AjaxPages_TransactionTypeAdd : AjaxPage
{
    private int ID
    {
        get
        {
            if (Request.Params["ttid"] != null || AjaxState.ContainsKey("ttid"))
            {
                if (!AjaxState.ContainsKey("ttid"))
                    AjaxState["ttid"] = Request.Params["ttid"];
                return Convert.ToInt32(AjaxState["ttid"]);
            }
            else
            {
                return 0;
            }
        }
    }


    private void AddData()
    {
        try
        {
            TransactionType objTransactionType = new TransactionType();            

            objTransactionType.Name = HtmlHelper.ControlValue(txtName.ClientID);

            objTransactionType.ModifiedDate = DateTime.Now;

            new TransactionTypeController().Add(objTransactionType);
            Response.Redirect("~/Admin/AjaxPages/TransactionTypeList.aspx");
        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = "<div class='error'>" + ex.Message + "</div>";
        }
    }

    private void EditData()
    {

        TransactionType objTransactionType = new TransactionType();

        objTransactionType.TransactionTypeID = ID;

        objTransactionType.Name = HtmlHelper.ControlValue(txtName.ClientID);

        objTransactionType.ModifiedDate = DateTime.Now;

        new TransactionTypeController().UpdateByTransactionTypeID(objTransactionType);
        Response.Redirect("~/Admin/AjaxPages/TransactionTypeList.aspx");
    }

    private void BindData()
    {
        var dataBunch = new TransactionTypeController().GetbyTransactionTypeID(ID);
        if (dataBunch.Count > 0)
        {
            var data = dataBunch[0];

            
            txtName.Text = data.Name;

            

        }
    }

    protected void AddAjaxClick(object sender, AjaxControl.AjaxEventArg e)
    {
        AddData();
        
    }
    public void PreventData()
    {
        txtName.Text = HtmlHelper.ControlValue(txtName.ClientID);
        

    }

    protected void UpdateAjaxClick(object sender, AjaxControl.AjaxEventArg e)
    {
        EditData();
    }
}